//
// Created by chaoy on 2023/2/26.
//
#include <iostream>

using namespace std;

struct ListNode {
    int data;
    struct ListNode *next;
    struct ListNode *back;
};

// 双链表的创建
void CreateDoubleNode(ListNode * phead)
{
    ListNode * head = phead;
    for(int i = 1;i<10;i++)
    {
        ListNode * temp = new ListNode;
        temp->back = head;
        temp->data = i;
        temp->next = NULL;
        head->next = temp;
        head = head->next;
    }
    return;

}

// 双链表添加
void AddDoubleNode(ListNode * phead)
{
    int num = 1;
    ListNode * head = phead;
    while (head->next != NULL)
    {
        head = head->next;
        if(num ==4)
        {
            ListNode * temp = new ListNode;
            temp->next = head->next;
            temp->back = head;
            temp->data = 666;
            head->next->back = temp;
            head->next =temp;

        }
        num ++;
    }

    return;
}
//双链表删除
void DeleteDoubleNode(ListNode * phead)
{
    int num = 1;
    ListNode * head = phead;
    while (head->next != NULL)
    {
        head = head->next;
        if (num ==4)
        {
            head->next->next->back = head;
            head->next = head->next->next;
        }
        num ++;

    }
    return;
}



// 双链表打印
void PrintDoubleNode(ListNode * phead)
{
    ListNode * head = phead;
    head = head->next;
    while (head!= NULL)
    {
        cout << head->data <<endl;
        head = head->next;
    }

    return;
}




int main() {
    ListNode *head = new ListNode;
    head->data = 0;
    head->next = NULL;
    head->back = NULL;

    CreateDoubleNode(head);
    //AddDoubleNode(head);
    DeleteDoubleNode(head);
    PrintDoubleNode(head);
    return 0;
}